package com.apps.ftapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.apps.ftapp.R;
import com.apps.ftapp.model.LianXiTiModel;
import com.apps.ftapp.util.Tools;

import java.util.List;

/**
 * Created by Administrator on 2017/10/23.
 */

public class SubjectResultAdapter extends BaseAdapter {


    private Context mContext;
    private List<LianXiTiModel.TestResultsBean> dataList;

    public SubjectResultAdapter(Context mContext, List<LianXiTiModel.TestResultsBean> dataList) {
        super();
        this.mContext = mContext;
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        if (null == dataList) {
            return 0;
        } else {
            return this.dataList.size();
        }
    }


    public void addRes(List<LianXiTiModel.TestResultsBean> data) {
        if (data != null) {
            this.dataList.clear();
            this.dataList.addAll(data);
            notifyDataSetChanged();
        }
    }

    @Override
    public Object getItem(int i) {
        if (dataList == null) {
            return null;
        } else {
            return this.dataList.get(i);
        }
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        LianXiTiModel.TestResultsBean tit = dataList.get(i);
        ViewHolder holder = null;
        if (view == null) {
            view = LayoutInflater.from(this.mContext).inflate(R.layout.activity_subject_result_gridview_item, null, false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        //判断是否答题

        //

        String isf = Tools.isNull(tit.getStatus());
        if ("right".equals(isf)) {
            holder.textView.setBackgroundResource(R.drawable.yyyy2);
        } else {
            holder.textView.setBackgroundResource(R.drawable.wrong);

        }

        holder.textView.setText(Tools.isIntNull(i) + 1 + "");
        return view;
    }


    private class ViewHolder {
        TextView textView;

        public ViewHolder(View view) {
            textView = view.findViewById(R.id.biao);
        }
    }
}
